import { IsString, IsNumber, IsOptional, Min, Max, IsBoolean } from 'class-validator';
import { Transform } from 'class-transformer';
import { ApiProperty } from '@nestjs/swagger';

export class BaziInfoDto {
  @ApiProperty({
    description: '出生时间，支持多种格式',
    example: '1990-01-01 12:00',
    type: String
  })
  @IsString()
  datetime: string;

  @ApiProperty({
    description: '性别，0-女，1-男',
    example: 1,
    minimum: 0,
    maximum: 1,
    type: Number
  })
  @IsNumber()
  @Min(0)
  @Max(1)
  @Transform(({ value }) => parseInt(value))
  gender: number;

  @ApiProperty({
    description: '姓名（可选）',
    example: '张三',
    required: false,
    type: String
  })
  @IsOptional()
  @IsString()
  name?: string;

  @ApiProperty({
    description: '经度（可选，用于计算真太阳时）',
    example: 116.3974,
    required: false,
    type: Number
  })
  @IsOptional()
  @IsNumber()
  @Transform(({ value }) => value === undefined || value === null || value === '' ? undefined : parseFloat(value))
  longitude?: number;

  @ApiProperty({
    description: '纬度（可选，用于计算真太阳时）',
    example: 39.9093,
    required: false,
    type: Number
  })
  @IsOptional()
  @IsNumber()
  @Transform(({ value }) => value === undefined || value === null || value === '' ? undefined : parseFloat(value))
  latitude?: number;

  @ApiProperty({
    description: '是否启用早晚子时支持',
    example: true,
    required: false,
    type: Boolean
  })
  @IsOptional()
  @IsBoolean()
  @Transform(({ value }) => value === 'true' || value === true)
  enableZiShiSupport?: boolean;
}

export class BaziDecadeDto {
  @ApiProperty({
    description: '出生时间，支持多种格式',
    example: '1990-01-01 12:00',
    type: String
  })
  @IsString()
  datetime: string;

  @ApiProperty({
    description: '性别，0-女，1-男',
    example: 1,
    minimum: 0,
    maximum: 1,
    type: Number
  })
  @IsNumber()
  @Min(0)
  @Max(1)
  @Transform(({ value }) => parseInt(value))
  gender: number;

  @ApiProperty({
    description: '是否启用早晚子时支持',
    example: true,
    required: false,
    type: Boolean
  })
  @IsOptional()
  @IsBoolean()
  @Transform(({ value }) => value === 'true' || value === true)
  enableZiShiSupport?: boolean;
}

export class BaziFortuneDto {
  @ApiProperty({
    description: '出生时间，支持多种格式',
    example: '1990-01-01 12:00',
    type: String
  })
  @IsString()
  datetime: string;

  @ApiProperty({
    description: '性别，0-女，1-男',
    example: 1,
    minimum: 0,
    maximum: 1,
    type: Number
  })
  @IsNumber()
  @Min(0)
  @Max(1)
  @Transform(({ value }) => parseInt(value))
  gender: number;

  @ApiProperty({
    description: '大运索引，从0开始',
    example: 1,
    minimum: 0,
    maximum: 10,
    type: Number
  })
  @IsNumber()
  @Min(0)
  @Max(10)
  @Transform(({ value }) => parseInt(value))
  decadeIndex: number;

  @ApiProperty({
    description: '是否启用早晚子时支持',
    example: true,
    required: false,
    type: Boolean
  })
  @IsOptional()
  @IsBoolean()
  @Transform(({ value }) => value === 'true' || value === true)
  enableZiShiSupport?: boolean;
}

export class BaziMonthDto {
  @ApiProperty({
    description: '出生时间，支持多种格式',
    example: '1990-01-01 12:00',
    type: String
  })
  @IsString()
  datetime: string;

  @ApiProperty({
    description: '性别，0-女，1-男',
    example: 1,
    minimum: 0,
    maximum: 1,
    type: Number
  })
  @IsNumber()
  @Min(0)
  @Max(1)
  @Transform(({ value }) => parseInt(value))
  gender: number;

  @ApiProperty({
    description: '大运索引，从0开始',
    example: 1,
    minimum: 0,
    maximum: 10,
    type: Number
  })
  @IsNumber()
  @Min(0)
  @Max(10)
  @Transform(({ value }) => parseInt(value))
  decadeIndex: number;

  @ApiProperty({
    description: '流年索引，从0开始',
    example: 0,
    minimum: 0,
    maximum: 9,
    type: Number
  })
  @IsNumber()
  @Min(0)
  @Max(9)
  @Transform(({ value }) => parseInt(value))
  fortuneIndex: number;

  @ApiProperty({
    description: '是否启用早晚子时支持',
    example: true,
    required: false,
    type: Boolean
  })
  @IsOptional()
  @IsBoolean()
  @Transform(({ value }) => value === 'true' || value === true)
  enableZiShiSupport?: boolean;
}

export class BaziDayDto {
  @ApiProperty({
    description: '出生时间，支持多种格式',
    example: '1990-01-01 12:00',
    type: String
  })
  @IsString()
  datetime: string;

  @ApiProperty({
    description: '性别，0-女，1-男',
    example: 1,
    minimum: 0,
    maximum: 1,
    type: Number
  })
  @IsNumber()
  @Min(0)
  @Max(1)
  @Transform(({ value }) => parseInt(value))
  gender: number;

  @ApiProperty({
    description: '大运索引，从0开始',
    example: 1,
    minimum: 0,
    maximum: 10,
    type: Number
  })
  @IsNumber()
  @Min(0)
  @Max(10)
  @Transform(({ value }) => parseInt(value))
  decadeIndex: number;

  @ApiProperty({
    description: '流年索引，从0开始',
    example: 0,
    minimum: 0,
    maximum: 9,
    type: Number
  })
  @IsNumber()
  @Min(0)
  @Max(9)
  @Transform(({ value }) => parseInt(value))
  fortuneIndex: number;

  @ApiProperty({
    description: '流月索引，从0开始',
    example: 0,
    minimum: 0,
    maximum: 11,
    type: Number
  })
  @IsNumber()
  @Min(0)
  @Max(11)
  @Transform(({ value }) => parseInt(value))
  monthIndex: number;

  @ApiProperty({
    description: '是否启用早晚子时支持',
    example: true,
    required: false,
    type: Boolean
  })
  @IsOptional()
  @IsBoolean()
  @Transform(({ value }) => value === 'true' || value === true)
  enableZiShiSupport?: boolean;
}

export class BaziHourDto {
  @ApiProperty({
    description: '出生时间，支持多种格式',
    example: '1990-01-01 12:00',
    type: String
  })
  @IsString()
  datetime: string;

  @ApiProperty({
    description: '性别，0-女，1-男',
    example: 1,
    minimum: 0,
    maximum: 1,
    type: Number
  })
  @IsNumber()
  @Min(0)
  @Max(1)
  @Transform(({ value }) => parseInt(value))
  gender: number;

  @ApiProperty({
    description: '大运索引，从0开始',
    example: 1,
    minimum: 0,
    maximum: 10,
    type: Number
  })
  @IsNumber()
  @Min(0)
  @Max(10)
  @Transform(({ value }) => parseInt(value))
  decadeIndex: number;

  @ApiProperty({
    description: '流年索引，从0开始',
    example: 0,
    minimum: 0,
    maximum: 9,
    type: Number
  })
  @IsNumber()
  @Min(0)
  @Max(9)
  @Transform(({ value }) => parseInt(value))
  fortuneIndex: number;

  @ApiProperty({
    description: '流月索引，从0开始',
    example: 0,
    minimum: 0,
    maximum: 11,
    type: Number
  })
  @IsNumber()
  @Min(0)
  @Max(11)
  @Transform(({ value }) => parseInt(value))
  monthIndex: number;

  @ApiProperty({
    description: '流日索引，从0开始',
    example: 0,
    minimum: 0,
    maximum: 30,
    type: Number
  })
  @IsNumber()
  @Min(0)
  @Max(30)
  @Transform(({ value }) => parseInt(value))
  dayIndex: number;

  @ApiProperty({
    description: '是否启用早晚子时支持',
    example: true,
    required: false,
    type: Boolean
  })
  @IsOptional()
  @IsBoolean()
  @Transform(({ value }) => value === 'true' || value === true)
  enableZiShiSupport?: boolean;
}

export class BaziPatternDto {
  @ApiProperty({
    description: '出生时间，支持多种格式',
    example: '1990-01-01 12:00',
    type: String
  })
  @IsString()
  datetime: string;

  @ApiProperty({
    description: '性别，0-女，1-男',
    example: 1,
    minimum: 0,
    maximum: 1,
    type: Number
  })
  @IsNumber()
  @Min(0)
  @Max(1)
  @Transform(({ value }) => parseInt(value))
  gender: number;

  @ApiProperty({
    description: '是否启用早晚子时支持',
    example: true,
    required: false,
    type: Boolean
  })
  @IsOptional()
  @IsBoolean()
  @Transform(({ value }) => value === 'true' || value === true)
  enableZiShiSupport?: boolean;
}

export class BaziReverseDto {
  @ApiProperty({
    description: '八字字符串，格式：甲子 乙丑 丙寅 丁卯',
    example: '甲子 乙丑 丙寅 丁卯',
    type: String
  })
  @IsString()
  sizhu: string;
}
